<?php

namespace App\Http\Controllers;

use App\Http\Service\Weibo\WeibopostService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

class WeibopostController extends BaseController
{
    private $getRules=[
            'type'=> 'required',
            //'city_code'=>'required',
        ];
    private  $getRulesMessage=[
            'type.required'=> 'type不能为空',
           // 'city_code.required'=> 'city_code不能为空',

        ];
    public $repository;
    public function __construct(WeibopostService $repository)
    {
        parent::__construct();
        $this->repository = $repository;
    }

    /**
     *  微博推送消息-weibo_post
     *  
     * @param Request $request
     * @return JsonResponse
     */
    public function addData(Request $request)
    {
        $data=[
            'unique_id'=>$request->json("article_id"),
            'article_id'=>$request->json("article_id"),
            'avatar'=>$request->json("avatar"),
            'user_id'=>$request->json("user_id"),
            'nickname'=>$request->json("nickname"),
            'comments'=>$request->json("comments"),
            'content'=>$request->json("content"),
            'images'=>$request->json("images"),
            'has_retweet'=>$request->json("has_retweet"),
            'publish_time'=>$request->json("publish_time"),
            'product_num'=>$request->json("product_num"),
            'retweeted_content'=>$request->json("retweeted_content",[]),
            'retweet_article_id'=>$request->json("retweet_article_id"),
            'article_detail_url'=>$request->json("article_detail_url"),
            'is_weibo_chaohua'=>$request->json("is_weibo_chaohua"),

        ];
        
        if(!empty($data['retweeted_content'])&&isset($data['retweeted_content'])){
            if(isset($data['retweeted_content']['comments'])){
                unset($data['retweeted_content']['comments']);
            }

        }
        //dd($data['retweeted_content']);
        $data['images'] = json_encode($data['images'], JSON_UNESCAPED_UNICODE);
        $data['content'] = json_encode($data['content'], JSON_UNESCAPED_UNICODE);
        $data['retweeted_content'] = json_encode($data['retweeted_content'], JSON_UNESCAPED_UNICODE);

        $data['comments'] = json_encode($data['comments'], JSON_UNESCAPED_UNICODE);
        //dd($data);
        $this->success1($this->repository->addData($request,$data));
    }
    //豆瓣-喜欢
    public function dbLike(Request $request)
    {
        $data=[
            'unique_id'=>$request->input("unique_id"),
            'people_id'=>$request->input("people_id"),
        ];
        $this->checkrule($data,$this->getRules2,$this->getRulesMessage2);
        $this->success($this->repository->dbLike($request,$data));

    }

    

  

}
